package com.guosifan.filter;

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

//@Component
//@WebFilter(urlPatterns = "")
public class UserFilter implements Filter {
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {

    }

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        HttpServletRequest request1 = (HttpServletRequest) request;
        HttpSession session = request1.getSession();
        HttpServletResponse response1 = (HttpServletResponse) response;
        Object obj = session.getAttribute("user");
        if(obj ==null){
            response1.sendRedirect("login.html");
        }
    }

    @Override
    public void destroy() {

    }
}
